angular.module('app').directive('appDetailInfo', ['$http', ($http) => {
  return {
    replace: true,
    restrict: 'AE',
    templateUrl: 'view/template/positionInfo.html',
    scope: {
      isActive: '=',
      isLogin: '=',
      data: '='
    },
    link: function ($scope) {
      $scope.$watch('data', function (newVal) {
        if (newVal) {
          $scope.data.select = $scope.data.select || false;
          $scope.imagePath = $scope.data.select ? 'image/star-active.png' : 'image/star.png';
        }
      })
      $scope.favorite = function () {
        $http.post('data/favorite.json', {
          id: $scope.data.id,
          select: !$scope.data.select
        }).success(function (resp) {
          $scope.data.select = !$scope.data.select;
          $scope.imagePath = $scope.data.select ? 'image/star-active.png' : 'image/star.png';
        });
      }
    }
  }
}]);
